/*
 * Erector.java
 *
 * Created on 2007. mC!rcius 12., 16:52
 *
 */

package laborhazi;

/**
 * Builder tool
 * @author nyuszik
 */
public class Erector extends Tool {
    private int power = 5;
    private Field field;
    /** Creates a new instance of Erector
     * @param f the Field
     */
    public Erector() {
    	
    }
    public Erector(Field f) {
    	field = f;
    }
    public String toString() {
    	return ("Erector");
    }
    /** 
     * Using the erector will create a stone if possible
     * @param lemming the lemming who uses the erector
     */
    public void use(Lemming lemming){
        if (checkPower()) {
        	power--;
            int[] position = new int[2];
            int[] pos = lemming.getPosition();
            position[0] = pos[0];
            position[1] = pos[1];
            int dir = lemming.getDir();
            int direction;
            if(dir == 0) {
            	direction = -1;
            } else direction = 1;
            position[0] = position[0] + direction;
            if (field.check(position) == null) {
            	field.put(new Stone(field), position);
            	lemming.setErecting(true);
            }
        } else {
            erase(lemming);
        }
    }
    /** 
     * Checks if the Erector has enough power left
     */
    private boolean checkPower() {
        if (power > 0) return true;
        else return false;
    }
    /** 
     * Removes the Erector
     */
    private void erase(Lemming lemming) {
    	lemming.removeTool(3);
    }
    
}
